package com.aftersale.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aftersale.demo.entity.Invitation;
import com.aftersale.demo.mapper.InvitationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 *
 */
@Component
public class InvitationServiceImpl{
    @Autowired
    InvitationMapper invitationMapper;
    @Scheduled(cron="0 48 20 * * ?")   //每天20：48执行一次
    public void execute(){
        int[] userId=invitationMapper.getSumCode();
        for (int i : userId) {
            String code=String.valueOf(new Random().nextInt(899999) + 100000);
            invitationMapper.setInvitationCode(i,code);
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //设置日期格式
        System.out.println("修改成功 " + df.format(new Date()));

    }


}




